// locutor
// (c) 2009, Normen Müller, normen.mueller@gmail.com  
// $Id: C.scala 88 2010-05-11 21:56:49Z normen.mueller $
package locutor.draft

import java.io.File

import scala.xml.XML.{loadFile}

import scaup.Views._

import scalaxx.diff.Command
import scalaxx.diff.Differ.{diff => sdiff}

///** Companion to <code>DocumentCollection</code> class.
// * 
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//object DocumentCollection {
//  
//  def apply(name: String, documents: (String, DocumentModel)*): DocumentCollection =
//    if(documents == null)
//      error("Documents may not be null.")
//    else apply(name, (Map[File,DocumentModel]() /: documents)((m,d) => d match {
//      case (document, model) if document.toFile.exists => m + {(document.toFile, model)}
//      case _                                           => error("Document \""+d._1+"\" does not exist.") 
//  }))  
//  
//  def apply(name: String, documents: Map[File, DocumentModel]): DocumentCollection =
//    if(documents == null)
//      error("Documents may not be null.")
//    else new DocumentCollection(name, (Map[File,DocumentModel]() /: documents)((m,e) => e match {
//      case (document, model) => m + {(document , DocumentModel(model.equivSys, model.graphModel join GraphModel.compute(loadFile(document)), model.ruleSys))}          
//    }))  
//  
//}

/** A document collection.
 * 
 * Each document must have an associated document model.
 * 
 * @todo maping from document types to document models
 * 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.5 */
//class DocumentCollection private [locutor] (name: String, documents: Map[File, DocumentModel]) extends Iterable[(File,DocumentModel)] {
//    
//  def elements = documents.elements
//  
//  /** Semantic difference analysis
//   * @return a mapping from each document within the collection to its corresponding sequence of edit operations turning BASE into WORKING. */
//  def analyze = (Map[File, List[Command]]() /: elements)((m,d) => d match {
//    case (working,model) => m + {(working, if(working.vc.versioned) sdiff(model.equivSys, working, working.vc.base.head) else Nil)}
//  })
//                                               
//  /** Semantic dependency analysis
//   * @return a dependency graph on the collection */                                               
//  def annotate: Map[File, DependencyGraph] = annotate(Map[File,File]())
//  
//  /** Semantic dependency analysis with additional user annotations.
//   * 
//   * @param annotations sequence of (document, annotation) pairs
//   * @todo may set ``annotations'' to implicit */
//  def annotate(annotations: (String, String)*): Map[File, DependencyGraph] = annotate((Map[File,File]() /: annotations.toList)((m,d) => d match {
//    case (document, annotation) if document.toFile.exists =>
//      if(annotation.toFile.exists)
//        m + {(document.toFile, annotation.toFile)}
//      else error("Annotation \""+annotation+"\" does not exist.")
//    case _  => error("Document \""+d._1+"\" does not exist.") 
//  }))
//  
//  /** Semantic dependency analysis with additional user annotations.
//   * 
//   * @param annotations sequence of (document, annotation) pairs
//   * @todo may set ``annotations'' to implicit */
//  def annotate(annotations: Map[File, File]): Map[File, DependencyGraph] = (Map[File, DependencyGraph]() /: elements)((m, d) => d match {
//    case (working,model) => m + {(working, DependencyGraph.compute(working, model.graphModel) /*join DependencyGraph.parse(annotations.get(working), model.graphModel)*/)}
//  })
//  
//  def ripple(dependencies: Map[File, DependencyGraph], deltas: Map[File, List[Command]]): ImpactGraph =
//    if((deltas == null) || (deltas.values.toList isEmpty))
//      ImpactGraph.empty
//    else if(dependencies == null)
//      error("")
//    else error("net yet implemented")    
//  
//  def ↩(deltas: Map[File, List[Command]])(implicit dependencies: Map[File, DependencyGraph]): ImpactGraph = ripple(dependencies, deltas)
//  
//} 
